#ifndef _IFLYTEK_ASR_INST_H
#define _IFLYTEK_ASR_INST_H
#include<string>
#include"asrInst.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//#define PBKDF2_SHA256_STATIC
//#define PBKDF2_SHA256_IMPLEMENTATION
#include <time.h>//only for linux
#include <ctype.h>//only for linux
#include <websocketpp/config/asio_client.hpp>
#include <websocketpp/client.hpp>

#include<mutex>
#include<condition_variable>
#include <iostream>
#include <stdlib.h>
#include"iflytekAsrRequestParam.h"
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include "../connection/wsConnection.h"
#include"../utils/log/recoProxyLog.h"
#include"../reporter/reporter.h"
using namespace speech;
using namespace rapidjson;
typedef websocketpp::client<websocketpp::config::asio_client> client;
typedef speech::wsConnection                                  wsConnection;
typedef std::shared_ptr<wsConnection>                         sConnection;
typedef vector< sConnection >                                 sConns;
//typedef websocketpp::client<websocketpp::config::asio_tls_client> client;

using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;

// pull out the type of messages sent by our config
typedef websocketpp::config::asio_client::message_type::ptr message_ptr;
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
typedef client::connection_ptr connection_ptr;
//typedef shared_ptr<speech::reporter> sReporter;

class iflytekAsrInst: public asrInst{
public:
	typedef iflytekAsrInst type;
	iflytekAsrInst(sReporter pReporter)
		:asrInst(pReporter),
		_requestParam(iflytekAsrRequestParam(getenv("RECO_VAD_APPID"), getenv("RECO_VAD_APIKEY"), getenv("RECO_VAD_APISECRET")))
	{
	}
	~iflytekAsrInst(){}
	int init()
	{
		return 0;	
	}
	void close(){
		//close all connection
		//_conns.clear();
	}
	int sendFirstMsg(int iMsgType,void* pBuf, int iBufLen, int iIndex)
	{
		//sReporter   resReporter = make_shared<reporter > (0,getCbFunc(),getCbObj());
		//start new connection
		getReporter()->createCon( _requestParam.createUrl(),getReporter()->createMsg(iIndex,RECO_CB_DATA));
		//getReporter()->reset(getReporter()->createMsg(iIndex,RECO_CB_DATA),getReporter()->createCon( _requestParam.createUrl()));
		sendMsg(iMsgType,pBuf,iBufLen);
		return 0;
	}
	int sendMsg(int iMsgType,void* pBuf, int iBufLen)
	{
		char forPrint[1024];
		sprintf(forPrint,"sendMsg Data Len %d, message type = %d",iBufLen, iMsgType);
#ifdef LOGFILE
		log::getInstance()->getLog()->info(forPrint);
#else
		printf("%s\n",forPrint);
#endif

		
		std::string msg = _requestParam.getFrame(iMsgType,pBuf,iBufLen);
		//_conns.back()->sendMsg(iMsgType,msg);
		getReporter()->sendMsg(iMsgType,msg);
		return 0;
	} 
private:


	iflytekAsrRequestParam       _requestParam;
	// a vecctor of connection
	//sConns                       _conns;
};
#endif
